<%@ page import="utils.StringUtils" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="database.*" %><%--
  Created by IntelliJ IDEA.
  User: jimmyhsu
  Date: 2016/12/19
  Time: 10:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%
        String studentId = request.getParameter("studentId");
        String courseIdStr = request.getParameter("courseId");
        PrintWriter writer = response.getWriter();
        if (StringUtils.isAnyoneEmpty(courseIdStr, studentId)) {
            writer.print("<script>location.href='comment.jsp';</script>");
        }
        int courseId = Integer.parseInt(courseIdStr);
        Course course = CourseDb.selectCourseById(courseId);
        CourseComment comment = CommentDb.selectComment(studentId, courseId);
    %>
    <title>对<%=course.getName()%>的评论</title>
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link href="../../static/css/bootstrap.css" rel="stylesheet">
    <style>
        .bottom-bar{
            width:100%;
            height:30px;
            position: absolute;
            bottom: 0;
        }
    </style>
</head>
<body>
<%@include file="checkStudentLogin.jsp"%>
<div class="navbar">
    <div class="navbar-inner">
        <a class="brand" href="#" style="color: #1abc9c;">青马班</a>
        <ul class="nav">
            <li><a href="signIn.jsp">签到</a></li>
            <li><a href="selectCourse.jsp">课程</a></li>
            <li class="active"><a href="comment.jsp">评价</a></li>
        </ul>
    </div>
</div>
<div id="banner"></div>

    <div class="help-block" style="text-align: center;">
        课程内容：
    <div class="btn-group" data-toggle="buttons-radio">
        <button class="btn btn-primary <%=comment!=null&&comment.getRating1()==1?"active":""%>" name="rating1" onclick="btnselected('rating1rs',1,this)">1</button>
        <button class="btn btn-primary <%=comment!=null&&comment.getRating1()==2?"active":""%>" name="rating1" onclick="btnselected('rating1rs',2,this)">2</button>
        <button class="btn btn-primary <%=comment!=null&&comment.getRating1()==3?"active":""%>" name="rating1" onclick="btnselected('rating1rs',3,this)">3</button>
        <button class="btn btn-primary <%=comment!=null&&comment.getRating1()==4?"active":""%>" name="rating1" onclick="btnselected('rating1rs',4,this)">4</button>
        <button class="btn btn-primary <%=comment!=null&&comment.getRating1()==5?"active":""%>" name="rating1" onclick="btnselected('rating1rs',5,this)">5</button>
    </div>
    </div>
    <div class="help-block" style="text-align: center;">
        教师水平：
        <div class="btn-group">
            <button class="btn btn-primary <%=comment!=null&&comment.getRating2()==1?"active":""%>" name="rating2" onclick="btnselected('rating2rs',1,this)">1</button>
            <button class="btn btn-primary <%=comment!=null&&comment.getRating2()==2?"active":""%>" name="rating2" onclick="btnselected('rating2rs',2,this)">2</button>
            <button class="btn btn-primary <%=comment!=null&&comment.getRating2()==3?"active":""%>" name="rating2" onclick="btnselected('rating2rs',3,this)">3</button>
            <button class="btn btn-primary <%=comment!=null&&comment.getRating2()==4?"active":""%>" name="rating2"  onclick="btnselected('rating2rs',4,this)">4</button>
            <button class="btn btn-primary <%=comment!=null&&comment.getRating2()==5?"active":""%>" name="rating2" onclick="btnselected('rating2rs',5,this)">5</button>
        </div>
    </div>
    <div class="help-block" style="text-align: center;">
        所得收获：
        <div class="btn-group">
            <button class="btn btn-primary <%=comment!=null&&comment.getRating3()==1?"active":""%>" name="rating3" onclick="btnselected('rating3rs',1,this)">1</button>
            <button class="btn btn-primary <%=comment!=null&&comment.getRating3()==2?"active":""%>" name="rating3" onclick="btnselected('rating3rs',2,this)">2</button>
            <button class="btn btn-primary <%=comment!=null&&comment.getRating3()==3?"active":""%>" name="rating3" onclick="btnselected('rating3rs',3,this)">3</button>
            <button class="btn btn-primary <%=comment!=null&&comment.getRating3()==4?"active":""%>" name="rating3" onclick="btnselected('rating3rs',4,this)">4</button>
            <button class="btn btn-primary <%=comment!=null&&comment.getRating3()==5?"active":""%>" name="rating3" onclick="btnselected('rating3rs',5,this)">5</button>
        </div>
    </div>
<form name="form" method="post" action="studentAddComment" style="text-align: center;">
    <input type="hidden" name="rating1rs" id="rating1rs" value="<%=comment==null?"":""+comment.getRating1()%>">
    <input type="hidden" name="rating2rs" id="rating2rs" value="<%=comment==null?"":""+comment.getRating2()%>">
    <input type="hidden" name="rating3rs" id="rating3rs" value="<%=comment==null?"":""+comment.getRating3()%>">
    <input type="hidden" name="courseId" id="courseId" value="<%=courseId%>">
    <input type="hidden" name="type" id="type" value="<%=comment==null?"insert":"update"%>">
<div class="help-block">
    点评：<textarea rows="3" name="textcomment" id="textcomment" placeholder="求点评~"><%=comment!=null?comment.getComment():""%></textarea>
</div>
    <div style="text-align: center;">
    <button class="btn btn-large btn-primary" type="button" onclick="check()">提交</button>
    </div>
</form>
<%@include file="footer.jsp"%>
<script src="../../static/js/jquery-1.10.2.js"></script>
<script src="../../static/js/bootstrap.js"></script>
</body>
<script type="text/javascript">
    function btnselected(group,score,btn) {
        document.getElementsByName(group)[0].value=score;
        var btns = document.getElementsByName(btn.name);
        for (var i = 0; i < btns.length; i++) {
            btns[i].className='btn btn-primary';
        }
        btn.className='btn btn-primary active';
    }
    var banner = document.getElementById("warningBanner");
    function check() {
        if (document.getElementsByName('rating1rs')[0].value == ""
            || document.getElementsByName('rating2rs')[0].value == ""
            || document.getElementsByName('rating3rs')[0].value == ""
            || $('#textcomment').val() == "") {
            showBanner(document.getElementById('textcomment').innerText);
            return;
        }
        document.form.submit();
    }
    function showBanner() {
        document.getElementById("banner").innerHTML="\<div class=\"alert\"\> <button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>\<strong\>提示\<\/strong\> 所有选项为必填\<\/div\>";
    }
</script>
</html>
